package QianFeng08.IteratorPatternDemo;
/**
 * 容器接口的具体实现类
 **/
public class ConcreteAggregate implements MyList{

    private Object[] elements;//对象数组
    private int size;//元素的个数
    private int index;
    public ConcreteAggregate() {
        elements = new Object[100];
    }

    @Override
    public void add(Object object) {
        elements[index++] = object;
        size++;
    }

    @Override
    public Object get(int index) {
        return elements[index];
    }

    @Override
    public Iterator iterator() {
        return new ConcreteIterator(this);
    }

    @Override
    public int getSize() {
        return size;
    }
}
